﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Scanner_Project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Scan_Button_Click(object sender, EventArgs e)
        {
            //string[] Lines = Code_TextBox.Text.Split(new char[] { '\n' });
            Scanner scanner = new Scanner(Code_TextBox.Text);

            Token CurrentToken = new Token();
            CurrentToken.Type = TokenType.Start;

            DataGridView1.Rows.Clear();
            DataGridView1.Columns.Clear();
            
            DataGridView1.Columns.Add("Token", "Token");
            DataGridView1.Columns.Add("Type", "Type");

            List<Token> Tokens = new List<Token>();

            while (CurrentToken.Type != TokenType.EndFile)
            {
                CurrentToken = scanner.GetToken();
                Tokens.Add(CurrentToken);
                //MessageBox.Show(CurrentToken.ToString());
            }

            DataGridView1.Rows.Add(Tokens.Count);

            for (int i = 0; i < Tokens.Count; i++)
            {
                DataGridView1[0, i].Value = Tokens[i].Lexeme;
                DataGridView1[1, i].Value = Tokens[i].Type;
            }
        }

        private void ChackSyntex_Button_Click(object sender, EventArgs e)
        {
            Parser parser = new Parser();
            bool Result = parser.IsSynaxCorrect(Code_TextBox.Text);
            MessageBox.Show(Result.ToString());
        }
    }
}
